#define BLINKER_MIOT_LIGHT
#define BLINKER_WIFI
#include <Blinker.h>

char auth[] = "93e8fadc01f5";
char ssid[] = "613专属";
char pswd[] = "613613613";

// 新建组件对象
BlinkerButton Button1("btn-abc");
// 按下按键即会执行该函数
void button1_callback(const String & state)
{
    BLINKER_LOG("get button state: ", state);
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
//小爱同学的电源类回调函数
void miotPowerState(const String & state)
{
    BLINKER_LOG("need set power state: ", state);

    if (state == BLINKER_CMD_ON) {
        digitalWrite(LED_BUILTIN, LOW);

        BlinkerMIOT.powerState("on");
        BlinkerMIOT.print();
    }
    else if (state == BLINKER_CMD_OFF) {
        digitalWrite(LED_BUILTIN, HIGH);

        BlinkerMIOT.powerState("off");
        BlinkerMIOT.print();
    }
}
void setup()
{
    // 初始化串口
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);
    BLINKER_DEBUG.debugAll();
    
    // 初始化有LED的IO
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);
    // 初始化blinker
    Blinker.begin(auth, ssid, pswd);
   // Blinker.attachData(dataRead);

    Button1.attach(button1_callback);  //注册按键回调函数
    BlinkerMIOT.attachPowerState(miotPowerState); //小爱同学电源注册回调函数
}

void loop() {
    Blinker.run();
}
